package org.example.Proxy;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;

public class ProxyTargetModel {
    private String regexStr = "";
    private String ip = "";

    private int port = 0;

    public String getRegexStr() {
        return regexStr;
    }

    public void setRegexStr(String regexStr) {
        this.regexStr = regexStr;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public ProxyTargetModel(String regexStr, String ip, int port) {
        this.regexStr = regexStr;
        this.ip = ip;
        this.port = port;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", ProxyTargetModel.class.getSimpleName() + "[", "]")
                .add("regexStr='" + regexStr + "'")
                .add("ip='" + ip + "'")
                .add("port=" + port)
                .toString();
    }

    /**
     * 转化list 为 map
     * @param models 映射的清单
     * @return 一个基于正则表达式的map，值为list中的对象
     */
    public static Map<String,ProxyTargetModel> coverListToMap(List<ProxyTargetModel> models){
        Map<String,ProxyTargetModel> modelMap = new HashMap<>(models.size());
        for (ProxyTargetModel model : models){
            modelMap.put(model.getRegexStr(),model);
        }
        return modelMap;
    }
}
